class Admin::BorrowRuleController < ApplicationController
  # specific layout
  layout 'admin/application'
  
  # list all borrow rules
  def index
    @borrow_rules = BorrowRule.paginate(:page => params[:page], :per_page => 10)
  end
  
  # add new borrow rule
  def new
    @borrow_rule = BorrowRule.new
  end
  def create
    @borrow_rule = BorrowRule.new(params[:borrow_rule])
    if @borrow_rule.save
       flash[:notice] = "Add new borrow rule successfully"
       redirect_to :controller => 'admin/borrow_rule', :action => 'view', :id => @borrow_rule.id
    else
       flash[:notice] = 'There some errors in processing'
       render 'new'
    end
  end
  
  # edit borrow rule
  def edit
    @borrow_rule = BorrowRule.find(params[:id])
  end
  def update
    borrow_rule = BorrowRule.find(params[:id])
    if borrow_rule.update_attributes(params[:borrow_rule])
      redirect_to :controller => 'admin/borrow_rule', :action => 'view', :id => borrow_rule.id
    else
      render 'edit'
    end
  end
  
  # view borrow rule
  def view
    @borrow_rule = BorrowRule.find(params[:id])
  end
  
  # delete a borrow rule
  def delete 
    borrow_rule = BorrowRule.find(params[:id])
    borrow_rule.destroy
    
    redirect_to :controller => 'admin/borrow_rule', :action => 'index'
  end
end
